package com.sxy.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author 宋鑫宇
 * @version 1.0
 */
@Component
@Aspect
public class ProjectAdvice {

    @Pointcut("execution(* com.sxy.service.*Service.*(..))")
    private void servicePt() {
    }

    @Around("ProjectAdvice.servicePt()")
    public Object runSpeed(ProceedingJoinPoint pjp) throws Throwable {
        Signature signature = pjp.getSignature();

        String className = signature.getName();

        String interfaceName = signature.getDeclaringTypeName();

        long start = System.currentTimeMillis();

        for (int i = 0; i < 1000; i++) {
            pjp.proceed();
        }
        long end = System.currentTimeMillis();
        System.out.println("业务层接口" + interfaceName + "." + className + "执行一万次时间：" + (end - start) + "ms");
        return null;
    }
}
